home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 1999 July / APC47-2.ISO / mac / macsbug / macsbug.hqx / MacsBug 6.5.4a6 / Building dcmds / C Samples / Vol.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-09-22  |  5.5 KB  |  245 lines

  1. /*
  2.     File:        Vol.c
  3.  
  4.     Contains:    A dcmd which dumps all volumes from the VCB queue.
  5.  
  6.     Written by:    JM3 = Jim Murphy
  7.                 DAL = Dave Lyons
  8.                 sad = Scott Douglas
  9.  
  10.     Copyright:    ⌐ 1988,1993-1994, 1996, 1998 by Apple Computer, Inc., all rights reserved.
  11.  
  12.     File Ownership:
  13.  
  14.         DRI:                Jim Murphy
  15.  
  16.         Other Contact:        Dave Lyons
  17.  
  18.         Technology:            MacsBug 6.5.x
  19.  
  20.     Writers:
  21.  
  22.         (DAL)    Dave Lyons
  23.         (sjb)    Steve Bollinger
  24.  
  25.     Change History (most recent first):
  26.  
  27.          <8>      1/6/98    DAL        Updated version number to 3.0.1.
  28.          <7>      1/5/98    sjb        Fix checks for locked volumes (hardware & software)
  29.          <6>   25-Jan-96    JM3        Updated the sample build commands to be current. Took out lowmem
  30.                                     define and included LowMem.h.
  31.          <5>   11-Dec-94    JM3        Updated for new version 3 dcmd requirements.
  32.          <4>   24-Jan-94    JM3        EqualString is now in TextUtils.h with the Universal Interfaces.
  33.          <2>     9/10/93    DAL        Fixed volume-name matching to work again (was using
  34.                                     non-prototyped "EQUALSTRING" instead of EqualString).  Widened
  35.                                     the volume-name column.  Changed "VCB at" to "VCB addr" and made
  36.                                     it align for 32-bit addresses.
  37.  
  38.     Modification history:
  39.         29Nov88 sad        revised for new dcmd names.  display more info.
  40.          5Oct88 sad        written.
  41.  
  42.     The following MPW commands will build the dcmd and copy it to the "Debugger Prefs" file
  43.     in the System folder. The dcmd's name in MacsBug will be the name of the file built by
  44.     the Linker.
  45.  
  46.     C Vol.c
  47.     Link -o Vol -sg Main=STDCLIB,STDIO,SANELIB dcmdGlue.a.o Put.c.o Vol.c.o" ╢
  48.         "{Libraries}Runtime.o" "{Libraries}Interface.o"
  49.     BuildDcmd Vol 198 -format3
  50.     Echo 'include "Vol";'    |    Rez -a -o "{systemFolder}Debugger Prefs"
  51.  
  52. */
  53.  
  54. #include <Types.h>
  55. #include <Memory.h>
  56. #include <OSUtils.h>
  57. #include <Files.h>
  58. #include <TextUtils.h>
  59. #include <LowMem.h>
  60.  
  61. #include "dcmd.h"
  62. #include "put.h"
  63.  
  64. static void DrawHdr()
  65. {
  66. //                             1         2         3         4         5         6         7
  67. //                    1234567890123456789012345678901234567890123456789012345678901234567890123456789
  68.     dcmdDrawLine("\pvRef Vol                  Flg dRef Drive FSID #Blk BlkSiz #Files #Dirs  Blsd Dir VCB addr");
  69.  
  70. }
  71.  
  72.  
  73. static void DrawVCB(VCB* vcbp)
  74. {
  75.  
  76.     PutUHexWord(vcbp->vcbVRefNum);
  77.     PutSpace();
  78.     PutPStrTruncTo(vcbp->vcbVN,15+10);
  79.     PutSpace();
  80.     PutChar((vcbp->vcbFlags & 0x8000) ? 'D' : 'd');
  81.     PutChar((vcbp->vcbAtrb & 0x0080) ? 'S' : 's');
  82.     PutChar((vcbp->vcbAtrb & 0x0040) ? 'H' : 'h');
  83.     PutSpace();
  84.     PutUHexWord(vcbp->vcbDRefNum);
  85.     PutSpace();
  86.     PutSpace();
  87.     PutUHexWord(vcbp->vcbDrvNum);
  88.     PutSpace();
  89.     PutUHexWord(vcbp->vcbFSID);
  90.     PutSpace();
  91.     PutUHexWord(vcbp->vcbNmAlBlks);
  92.     PutSpace();
  93.     PutUHexZTo(vcbp->vcbAlBlkSiz,6,47+10);
  94.     PutSpace();
  95.     PutUHexZTo(vcbp->vcbFilCnt,6,54+10);
  96.     PutSpace();
  97.     PutUHexZTo(vcbp->vcbDirCnt,6,61+10);
  98.     PutSpace();
  99.     PutUHexZTo(vcbp->vcbFndrInfo[0],6,70+10);
  100.     PutSpace();
  101.     PutUHexZTo((unsigned long)vcbp,8,77+10);
  102.     PutLine();
  103.  
  104. }
  105.  
  106.  
  107. // PrefixPStr
  108. //
  109. // Returns true if astr is equal to a prefix of bstr.
  110. // astr must not be longer than 31 characters.
  111.  
  112. static Boolean PrefixPStr(const Str255 astr, const Str255 bstr)
  113. {
  114.  
  115.     char newstr[32];
  116.     int alen = *astr;
  117.     int blen = *bstr;
  118.  
  119.     if (alen <= blen)
  120.     {
  121.         BlockMove(bstr+1,newstr+1,alen);
  122.         newstr[0] = alen;
  123.         return EqualString(astr,newstr,false,true);
  124.     }
  125.  
  126.     return false;    
  127.  
  128. }
  129.  
  130.  
  131.  
  132. pascal void CommandEntry(dcmdBlock* paramPtr)
  133. {
  134.  
  135.     static const char usageStr[] = "\p[vRefNum|drvNum|\"vol name\"]";
  136.  
  137.     switch (paramPtr->request)
  138.     {
  139.         case dcmdInit:
  140.             break;
  141.  
  142.         case dcmdHelp:
  143.             dcmdDrawLine("\pDisplays volume information for the given vrefnum, volume name or all");
  144.             dcmdDrawLine("\pmounted volumes. Flags are D/d=Dirty, S/s=Software locked,");
  145.             dcmdDrawLine("\pH/h=Hardware locked.");
  146.             break;
  147.  
  148.         case dcmdGetInfo:
  149.             * (long *) &((GetInfoRequestBlockPtr) paramPtr->requestIOBlock)->dcmdVersion = 0x03018000; // version 3.0.1 final
  150.             BlockMoveData(&usageStr, &((GetInfoRequestBlockPtr) paramPtr->requestIOBlock)->usageStr, usageStr[0]+1);
  151.             break;
  152.  
  153.         case dcmdDoIt:
  154.         {
  155.             Boolean    doOneVCB = false;
  156.             long    vref;
  157.             short    c;
  158.             Boolean    haveVolName = false;
  159.             Str255    volname;
  160.             VCB*    vcbp;
  161.             int        numvcbs = 0;
  162.             Boolean    foundOne = false;
  163.  
  164.             dcmdSwapWorlds();
  165.  
  166.             dcmdDrawLine("\pDisplaying Volume Control Blocks");
  167.  
  168.             // get low-memory values after dcmdSwapWorlds()
  169.             vcbp = (VCB*) (LMGetVCBQHdr()->qHead);
  170.  
  171.             c = dcmdPeekAtNextChar();
  172.             if (c == '"' || c == '\'')
  173.             {
  174.                 haveVolName = true;
  175.                 (void) dcmdGetNextParameter(volname);
  176.             }
  177.             else
  178.             {
  179.                 (void) dcmdGetNextExpression(&vref, &doOneVCB);
  180.             }
  181.  
  182.             if (doOneVCB)
  183.                 vref = (short) vref;
  184.  
  185.             while (vcbp)
  186.             {
  187.                 if ((doOneVCB && (vcbp->vcbVRefNum == vref || vcbp->vcbDrvNum == vref)) ||
  188.                     (haveVolName && PrefixPStr(volname,vcbp->vcbVN)) ||
  189.                     (!doOneVCB && !haveVolName))
  190.                 {
  191.                     numvcbs++;
  192.                     if (!foundOne)
  193.                     {
  194.                         DrawHdr();
  195.                         foundOne = true;
  196.                     }
  197.                     DrawVCB(vcbp);
  198.                 }
  199.                 if (paramPtr->aborted)
  200.                     break;
  201.                 if (vcbp->qLink == 0)
  202.                     if (vcbp != (VCB*)(LMGetVCBQHdr()->qTail))
  203.                         dcmdDrawLine("\pVCB queue does not end at VCBQHdr.qTail");
  204.                 vcbp = (VCB*)vcbp->qLink;
  205.             }
  206.  
  207.             if (!paramPtr->aborted)
  208.             {
  209.                 if (haveVolName || doOneVCB)
  210.                 {
  211.                     if (!foundOne)
  212.                         if (haveVolName)
  213.                         {
  214.                             PutPStr("\pNo mounted volumes match \"");
  215.                             PutPStr(volname);
  216.                             PutChar('"');
  217.                             PutLine();
  218.                         }
  219.                         else
  220.                         {
  221.                             PutPStr("\pNo mounted volumes match ");
  222.                             PutUHexWord(vref);
  223.                             PutLine();
  224.                         }
  225.                 }
  226.                 else
  227.                 {
  228.                     PutUDec(numvcbs);
  229.                     PutPStr("\p VCBs");
  230.                     PutLine();
  231.                 }
  232.             }
  233.  
  234.             dcmdSwapWorlds();
  235.             break;
  236.         }
  237.  
  238.         // Version 3 and newer dcmds must quietly ignore requests we don't recognize.
  239.  
  240.         default:
  241.             break;
  242.     }
  243.  
  244. } // CommandEntry
  245.